
cjson = require "cjson.safe"
local redis = require "resty.redis"
local stats_redis_key = "dist-wrk-stats"

local red = redis:new()
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then 
    log(ERR, err)
    return
end

ngx.req.read_body()
local body = cjson.decode(ngx.req.get_body_data())

local metric_name = body.targets[1].data.metric_name
local taskid = body.targets[1].data.taskid
local field = string.format("%s-%s", taskid, metric_name)
print("field = ", field)
local resp = red:hget(stats_redis_key, field)

ngx.say(resp)
